# -*- coding: utf-8 -*-
from datetime import timedelta
from jms_hi.ods.tms.yl_tmsnew_branch_shipment_stop_hi import jms_ods__yl_tmsnew_branch_shipment_stop_hi
from jms_hi.ods.tms.yl_tmsnew_tms_shipment_hf import jms_ods__yl_tmsnew_tms_shipment_hf
from jms_hi.ods.tms.yl_tmsnew_branch_shipment_hi import jms_ods__yl_tmsnew_branch_shipment_hi
from jms_hi.ods.tms.yl_tmsnew_tms_shipment_stop_hf import jms_ods__yl_tmsnew_tms_shipment_stop_hf

from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from airflow.providers.apache.hdfs.sensors.web_hdfs import WebHdfsSensor

jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi = SparkSqlOperator(
    task_id='jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi',
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    master='yarn',
    name='jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi_{{ execution_date | cst_hour }}',
    sql='jms_hi/dwd/tms/dwd_tmsnew_shipment_stop_union_base_hi/execute.hql',
    pool_slots=4,
    #executor_cores=4,
    executor_cores=2,
    executor_memory='8G',
    #executor_memory='4G',
    #num_executors=8,
    num_executors=4,
    conf={'spark.dynamicAllocation.enabled': 'true',
          'spark.shuffle.service.enabled': 'true',
          #'spark.dynamicAllocation.maxExecutors': 20,
          'spark.dynamicAllocation.maxExecutors'             : 5,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 30,
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',
          'spark.executor.memoryOverhead': '2G',
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 150,  # 最大分区
              'hive.exec.max.dynamic.partitions.pernode': 300,  # 最大分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
    retries=2,
    sla=timedelta(hours=2), )
jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi << [
    jms_ods__yl_tmsnew_tms_shipment_hf,
    jms_ods__yl_tmsnew_branch_shipment_stop_hi,
    jms_ods__yl_tmsnew_branch_shipment_hi,
    jms_ods__yl_tmsnew_tms_shipment_stop_hf
]
